<?php

class Sistema_Form_Usuarios extends Zend_Form
{

    public function init()
    {
        $front = Zend_Controller_Front::getInstance();
        $controller = $front->getRequest()->getControllerName();
        $module = $front->getRequest()->getModuleName();
        $url = $front->getBaseUrl().'/'.$module.'/'.$controller;
        
        $this->setName('form_pdr');
        
        $id = $front->getRequest()->getParam('id', 0);
        
        $_PER_ID = Zend_Auth::getInstance()->getStorage()->read()->PER_ID;
        
        $el = new Zend_Form_Element_Hidden('USU_ID',array('disableLoadDefaultDecorators' =>true));
        $el->addDecorators(array(array('ViewHelper'),array('Errors')))->addFilter('Int');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('USU_NOME');
        $el->setLabel('Nome')->setRequired(true);
        $el->setAttrib('required','');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('USU_EMAIL');
        $el->setLabel('E-mail')->setRequired(true);
        $el->setAttrib('class','email');
        $el->setAttrib('required','');
        $this->addElement($el);
        
        $el= new Zend_Form_Element_Text('USU_LOGIN');
        $el->setLabel('Login')->setRequired(true);
        $el->setAttrib('required','');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Password('USU_SENHA');
        $el->setLabel('Senha');
        if($id == 0) $el->setAttrib('required','');
        $this->addElement($el);
        
        
        $obj = new Sistema_Model_DbTable_Permissao();
        $row = $obj->fetchAll()->toArray();
        $arr = array();
        foreach($row as $r) $arr[$r['PER_ID']] = $r['PER_NOME']; 
        
        if($_PER_ID <= 2) {
            $el = new Zend_Form_Element_Select('PER_ID',array('onchange' => ''));
            $el->setLabel('Permissão')->setRequired(true)
            ->addMultiOptions($arr);
            $el->setAttrib('required','');
            $this->addElement($el);
        }
        
        if($_PER_ID <= 2) {
            $el = new Zend_Form_Element_Checkbox('USU_STA',array('checked'=>'checked'));
            $el->setLabel('Status');
            $this->addElement($el);
        }
        
        $btn = new Zend_Form_Element_Submit('Salvar',array('disableLoadDefaultDecorators' =>true));
        $btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setAttrib('id', 'submitbutton');
        $btn->setAttrib('class', 'btn-frm');
        $this->addElement($btn);
        
        $btn = new Zend_Form_Element_Button('Cancelar',array('disableLoadDefaultDecorators' =>true));
        //$btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setDecorators(array(array('Description', array('escape' => false, 'tag' => false))));
        $btn->setDescription('<a href="'.$url.'" class="btn-frm">Voltar</a>');
        $btn->setAttrib('id', 'btncancel');
        $btn->setAttrib('class', 'btn-frm');
        $this->addElement($btn);
        
    }


}

